package com.example.simpletodolist;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import android.util.Log;

public class DateTimeParser {
	public static Calendar parse(String datePattern, String timePattern, String date, String time) throws ParseException
	{
		SimpleDateFormat df = new SimpleDateFormat(timePattern);
		Date tempDate = df.parse(time);
		Calendar calTime = new GregorianCalendar();
		calTime.setTime(tempDate);
		df = new SimpleDateFormat(datePattern);
		tempDate=df.parse(date);
		Calendar calDate = new GregorianCalendar();
		calDate.setTime(tempDate);

		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.MINUTE, 		calTime.get(Calendar.MINUTE));
		calendar.set(Calendar.HOUR_OF_DAY, 	calTime.get(Calendar.HOUR_OF_DAY));
		
		calendar.set(Calendar.MONTH, 		calDate.get(Calendar.MONTH));
		calendar.set(Calendar.DAY_OF_MONTH, calDate.get(Calendar.DAY_OF_MONTH));
		calendar.set(Calendar.YEAR, 		calDate.get(Calendar.YEAR));
		Log.d("date/time", calendar.toString());
		
		
		return calendar;
	}
	public static Calendar parse(String pattern, String strDateTime) throws ParseException
	{
		SimpleDateFormat df = new SimpleDateFormat(pattern);
		Date tempDate=df.parse(strDateTime);
		Calendar currentDateTime = new GregorianCalendar();
		currentDateTime.setTime(tempDate);

		Calendar calendar = new GregorianCalendar();
		
		calendar.set(Calendar.MONTH, 		currentDateTime.get(Calendar.MONTH));
		calendar.set(Calendar.DAY_OF_MONTH, currentDateTime.get(Calendar.DAY_OF_MONTH));
		calendar.set(Calendar.YEAR, 		currentDateTime.get(Calendar.YEAR));
		calendar.set(Calendar.HOUR_OF_DAY, currentDateTime.get(Calendar.HOUR_OF_DAY));
		calendar.set(Calendar.MINUTE, currentDateTime.get(Calendar.MINUTE));
		Log.d("date/time", calendar.toString());
		
		
		return calendar;
	}

	public static String getTimeString(String timePattern, int hourOfDay, int minute)
	{
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
		calendar.set(Calendar.MINUTE, minute);
		SimpleDateFormat df = new SimpleDateFormat(timePattern);
		Log.d(timePattern, df.format(calendar.getTime()));
		
		return df.format(calendar.getTime());
	}
	public static String getDateString(String datePattern, int month, int dayOfMonth, int year)
	{
		Calendar calendar = new GregorianCalendar();
		calendar.set(Calendar.MONTH, month);
		calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
		calendar.set(Calendar.YEAR, year);
		SimpleDateFormat df = new SimpleDateFormat(datePattern);
		Log.d(datePattern, df.format(calendar.getTime()));
		
		return df.format(calendar.getTime());
	}
}
